/**  
 * All rights Reserved, Designed By www.woniuxy.com
 * @Title:  Account.java   
 * @Package com.woniu.domain   
 * @Description:    Description  
 * @author: 蜗牛学院  
 * @date:   2019年8月24日 上午11:23:15
 * @user:   Administrator  
 * @version V1.0 
 * @Copyright: 2019 www.woniuxy.com Inc. All rights reserved. 
 * 注意：本内容仅限于成都蜗牛创想科技有限公司，禁止外泄以及用于其他的商业目
 */ 
package com.woniu.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionContext;
import com.woniu.domain.Collect;
import com.woniu.domain.MusicType;
import com.woniu.service.MusicService;
import com.woniu.utils.PageBean;
import com.woniu.utils.Queryv;

/**
 * @author Administrator
 *
 */
@Controller
@Scope("prototype")
public class MusicAction {
	private Queryv query;
	private Collect collect;
	@Autowired
	MusicService ms;
	public String list() {
		PageBean pb = ms.findMusicList(query);
		ActionContext.getContext().getSession().put("pb", pb);		
		return "list";
	}
	public void showType() throws IOException {
		HttpServletResponse resp = ServletActionContext.getResponse();
		resp.setCharacterEncoding("utf-8");
		PrintWriter out = resp.getWriter();
		List<MusicType> lists = ms.findAllType();
		Gson gson = new Gson();
		String category = gson.toJson(lists);
		out.print(category);
	}
	public void collect() throws IOException {
//		System.out.println(collect.getMusic().getMid());
		HttpServletResponse resp = ServletActionContext.getResponse();
		resp.setCharacterEncoding("utf-8");
		PrintWriter out = resp.getWriter();
		ms.collectMusic(collect);		
		out.print("1");
		
		//return "list";
	}
	public String collectList() {
		List<Collect> list = ms.findCollectList(collect);
		ActionContext.getContext().put("lists", list);
		return "collectList";
	}
	/**
	 * @return the query
	 */
	public Queryv getQuery() {
		return query;
	}
	/**
	 * @param query the query to set
	 */
	public void setQuery(Queryv query) {
		this.query = query;
	}
	/**
	 * @return the collect
	 */
	public Collect getCollect() {
		return collect;
	}
	/**
	 * @param collect the collect to set
	 */
	public void setCollect(Collect collect) {
		this.collect = collect;
	}
	
}
